<template>
  <view class="box">
    <view class="header">
      <view class="h-item active">
        <view class="h-icon">
          <text class="iconfont icon-shenfenzheng"></text>
        </view>
        <text class="h-txt">实名认证</text>
      </view>
      <view class="h-item active">
        <view class="h-icon">
          <text class="iconfont icon-creditcard-fill"></text>
        </view>
        <text class="h-txt">添加银行卡</text>
      </view>
      <view class="h-item">
        <view class="h-icon"><text class="icon-qiandai iconfont"></text></view>
        <text class="h-txt">审核下款</text>
      </view>
    </view>
    <view class="desc">请绑定常用银行卡，否则将严重影响通过率</view>
    <view class="title">银行卡信息认证</view>
    <view class="form-box">
      <u-form :model="form" label-width="150" ref="uForm">
        <u-form-item label="持卡人">
          <u-input disabled placeholder="请输入持卡人姓名" v-model="form.userName"/>
        </u-form-item>
        <u-form-item  label="选择银行">
          <u-input  placeholder="请选择" @click="show = true" v-model="form.address" type="select"/>
          <u-action-sheet :safe-area-inset-bottom="true" :cancel-btn="false" :tips="{text:'请选择银行卡类型(信用卡不支持)'}" :list="actionSheetList" v-model="show" @click="actionSheetCallback"></u-action-sheet>
        </u-form-item>
        <u-form-item label="银行卡号">
          <u-input type="number" placeholder="请输入本人银行卡号" v-model="form.banknumber"/>
        </u-form-item>
        <u-form-item  label="预留手机号">
          <u-input type="number" placeholder="请输入预留手机号"   v-model="form.bankphone" />
        </u-form-item>
      </u-form>
    </view>
    <view class="btn-box">
      <u-button @click="handleSubmit" ripple shape="circle" type="primary">下一步</u-button>
    </view>
    <u-mask :show="show3">
      <view  @tap.stop class="warp">
        <view class="rect">
          <u-icon class="icon" @click="show3 = false" name="close-circle" color="#bbb" size="38"></u-icon>
          <u-form class="form-box1">
            <u-form-item :border-bottom="false" style="margin-top: 45rpx;padding-right: 0" class="form-item">
              <view slot="right"><u-button @click="getCode" size="mini"  ripple type="primary">{{tips}}</u-button></view>
              <u-input  placeholder="请输入验证码" v-model="form.pcode" />
            </u-form-item>
            <u-form-item>
              <u-button ripple style="width: 100%" size="medium" type="primary">确认</u-button>
            </u-form-item>
          </u-form>
        </view>
      </view>
    </u-mask>
    <u-verification-code :seconds="seconds" ref="uCode"
                         @change="codeChange"></u-verification-code>
  </view>
</template>

<script>
import {bank} from "../../api";

export default {
  name: "attest1",
  data() {
    return {
      form: {
        userName: ''
      },
      tips:'获取验证码',
      show3:false,
      show: false,
      show2:false,
      seconds:60,
      userInfo:{},
      actionSheetList:[
        {
          text: '工商银行'
        },
        {
          text: '建设银行'
        },
        {
          text: '邮政银行'
        },
        {
          text: '邮政银行'
        },
        {
          text: '中信银行'
        },
        {
          text: '平安银行'
        },
        {
          text: '华夏银行'
        },
        {
          text: '上海银行'
        },
      ],
    }
  },
  onLoad(){
    const { userName,userId} =this.$store.getters.getUserInfo
    console.log(this.$store.getters.getUserInfo)
    this.form.userName = userName
    this.form.userId = userId
  },
  methods:{
    codeChange(text) {
      this.tips = text;
    },
    handleSubmit(){
      uni.showLoading({
        title:'正在提交',
        mask:true
      })
      bank(this.form).then(()=>{
        uni.hideLoading()
        uni.redirectTo({
          url:'/pages/user/attest3'
        })
      })
    },
    getCode() {
      if(this.$refs.uCode.canGetCode) {
        // 模拟向后端请求验证码
        uni.showLoading({
          title: '正在获取验证码'
        })
        setTimeout(() => {
          uni.hideLoading();
          // 这里此提示会被this.start()方法中的提示覆盖
          this.$u.toast('验证码已发送');
          // 通知验证码组件内部开始倒计时
          this.$refs.uCode.start();
        }, 2000);
      } else {
        this.$u.toast('倒计时结束后再发送');
      }
    },
    actionSheetCallback(index) {
      this.form.address = this.actionSheetList[index].text;
    }
  }
}
</script>

<style scoped lang="scss">

@import '~@/static/font/iconfont.scss';
page{
  touch-action: none;
}
.header {
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: 100rpx;
  background-color: #fff;

  .h-item {
    box-sizing: border-box;
    position: relative;
    width: 200rpx;
    height: 50rpx;
    line-height: 46rpx;
    text-align: center;
    border-radius: 50rpx;
    border: 2rpx solid #999;
    font-size: 24rpx;

    .h-icon {
      position: absolute;
      left: -20rpx;
      top: 50%;
      transform: translateY(-50%);
      width: 56rpx;
      height: 56rpx;
      display: flex;
      justify-content: center;
      align-items: center;
      border-radius: 50%;
      border: 2rpx solid #999;
      background-color: #fff;
      color: #bbb;
    }

    .h-txt {
      letter-spacing: 1px;
    }

    &.active {
      background-color: #2E82E7;
      color: #fff;
      border-color: #fff;

      .h-icon {
        background-color: #2E82E7;
        border-color: #fff;
        color: #fff;
      }
    }
  }
}
.desc {
  height: 80rpx;
  line-height: 80rpx;
  text-align: center;
  background-color: #eee;
  color: #999;
}
.title {
  font-size: 30rpx;
  text-align: center;
  line-height: 100rpx;
}
.form-box {
  width: 700rpx;
  border: 1px solid #ddd;
  margin: 0 auto;
  box-sizing: border-box;
  padding: 0 40rpx 10rpx;
  border-radius: 10rpx;
}
.btn-box{
  margin: 80rpx 60rpx 0;
}


.rect {
  position: absolute;
  left: 50%;
  top: 40%;
  width: 580rpx;
  transform: translate(-50%,-50%);
  background-color: #fff;
  border-radius: 20rpx;
  padding: 0 40rpx;
  .form-box1{
    margin-top: 60rpx;
  }
  .icon{
    position: absolute;
    top: 20rpx;
    right: 20rpx;
  }
}
</style>
